]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Add 'Notifications' switch to tray menu
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 30 Sep 2013 14:47:52 +0000 (16:47 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 10 Oct 2013 21:13:47 +0000 (23:13 +0200)
According to the designs, the notifications switch was supposed
to move from the user menu to the new message tray menu. However
so far the new system status implementation only removed the old
switch, so add it back in its new place now.

https://bugzilla.gnome.org/show_bug.cgi?id=707073

js/ui/messageTray.js

index e98be02f739e22d18973f6afc64fdcfa1922408e..d8d1e36a367471e2d49d89a832ce19f1eba00d39 100644 (file)
@@ -1507,9 +1507,33 @@ const MessageTrayMenu = new Lang.Class({
 
         this._tray = tray;
 
+        this._presence = new GnomeSession.Presence(Lang.bind(this, function(proxy, error) {
+            if (error) {
+                logError(error, 'Error while reading gnome-session presence');
+                return;
+            }
+
+            this._onStatusChanged(proxy.status);
+        }));
+        this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
+            this._onStatusChanged(status);
+        }));
+
+        this._accountManager = Tp.AccountManager.dup();
+        this._accountManager.connect('most-available-presence-changed',
+                                     Lang.bind(this, this._onIMPresenceChanged));
+        this._accountManager.prepare_async(null, Lang.bind(this, this._onIMPresenceChanged));
+
         this.actor.hide();
         Main.layoutManager.addChrome(this.actor);
 
+        this._busyItem = new PopupMenu.PopupSwitchMenuItem(_("Notifications"));
+        this._busyItem.connect('toggled', Lang.bind(this, this._updatePresence));
+        this.addMenuItem(this._busyItem);
+
+        let separator = new PopupMenu.PopupSeparatorMenuItem();
+        this.addMenuItem(separator);
+
         this._clearItem = this.addAction(_("Clear Messages"), function() {
             let toDestroy = [];
             let sources = tray.getSources();
@@ -1541,9 +1565,43 @@ const MessageTrayMenu = new Lang.Class({
         settingsItem.connect('activate', function() { tray.close(); });
     },
 
+    _onStatusChanged: function(status) {
+        this._sessionStatus = status;
+        this._busyItem.setToggleState(status != GnomeSession.PresenceStatus.BUSY);
+    },
+
+    _onIMPresenceChanged: function(am, type) {
+        if (type == Tp.ConnectionPresenceType.AVAILABLE &&
+            this._sessionStatus == GnomeSession.PresenceStatus.BUSY)
+            this._presence.SetStatusRemote(GnomeSession.PresenceStatus.AVAILABLE);
+    },
+
     _updateClearSensitivity: function() {
         this._clearItem.setSensitive(this._tray.clearableCount > 0);
     },
+
+    _updatePresence: function(item, state) {
+        let status = state ? GnomeSession.PresenceStatus.AVAILABLE
+                           : GnomeSession.PresenceStatus.BUSY;
+        this._presence.SetStatusRemote(status);
+
+        let [type, s ,msg] = this._accountManager.get_most_available_presence();
+        let newType = 0;
+        let newStatus;
+        if (status == GnomeSession.PresenceStatus.BUSY &&
+            type == Tp.ConnectionPresenceType.AVAILABLE) {
+            newType = Tp.ConnectionPresenceType.BUSY;
+            newStatus = 'busy';
+        } else if (status == GnomeSession.PresenceStatus.AVAILABLE &&
+                 type == Tp.ConnectionPresenceType.BUSY) {
+            newType = Tp.ConnectionPresenceType.AVAILABLE;
+            newStatus = 'available';
+        }
+
+        if (newType > 0)
+            this._accountManager.set_all_requested_presences(newType,
+                                                             newStatus, msg);
+    }
 });
 
 const MessageTrayMenuButton = new Lang.Class({